﻿using System;
using System.Collections.Generic;
using System.IO;

namespace ProjScan.Tools
{
	// Token: 0x02000164 RID: 356
	internal class FileStreamFactory : Singleton<FileStreamFactory>
	{
		// Token: 0x06000CB5 RID: 3253 RVA: 0x000388E8 File Offset: 0x00036AE8
		public StreamWriter GetStreamWriter(string filePath)
		{
			StreamWriter streamWriter;
			bool flag = this._writers.TryGetValue(filePath, out streamWriter);
			StreamWriter result;
			if (flag)
			{
				bool flag2 = streamWriter.BaseStream != null;
				if (flag2)
				{
					result = streamWriter;
				}
				else
				{
					result = new StreamWriter(filePath);
				}
			}
			else
			{
				streamWriter = new StreamWriter(filePath);
				streamWriter.AutoFlush = true;
				this._writers.Add(filePath, streamWriter);
				result = streamWriter;
			}
			return result;
		}

		// Token: 0x06000CB6 RID: 3254 RVA: 0x00038948 File Offset: 0x00036B48
		public StreamWriter GetEncryptedStreamWriter(string filePath)
		{
			return null;
		}

		// Token: 0x06000CB7 RID: 3255 RVA: 0x0003895C File Offset: 0x00036B5C
		public StreamWriter GetStreamWriter(string filePath, bool append)
		{
			StreamWriter streamWriter;
			bool flag = this._writers.TryGetValue(filePath, out streamWriter);
			StreamWriter result;
			if (flag)
			{
				bool flag2 = streamWriter.BaseStream != null;
				if (flag2)
				{
					result = streamWriter;
				}
				else
				{
					result = new StreamWriter(filePath, append);
				}
			}
			else
			{
				streamWriter = new StreamWriter(filePath, append);
				streamWriter.AutoFlush = true;
				this._writers.Add(filePath, streamWriter);
				result = streamWriter;
			}
			return result;
		}

		// Token: 0x06000CB8 RID: 3256 RVA: 0x000067A9 File Offset: 0x000049A9
		public void CloseStreamWriter(StreamWriter writer)
		{
			writer.Close();
			writer.Dispose();
		}

		// Token: 0x06000CB9 RID: 3257 RVA: 0x000067BA File Offset: 0x000049BA
		public void CloseAllStreams()
		{
			this.CloseAllWriters();
			this.CloseAllReaders();
		}

		// Token: 0x06000CBA RID: 3258 RVA: 0x000389BC File Offset: 0x00036BBC
		public void CloseAllWriters()
		{
			foreach (StreamWriter streamWriter in this._writers.Values)
			{
				bool flag = streamWriter != null;
				if (flag)
				{
					streamWriter.Close();
					streamWriter.Dispose();
				}
			}
			this._writers.Clear();
		}

		// Token: 0x06000CBB RID: 3259 RVA: 0x00038A38 File Offset: 0x00036C38
		public StreamReader GetStreamReader(string filePath)
		{
			StreamReader streamReader;
			bool flag = this._readers.TryGetValue(filePath, out streamReader);
			StreamReader result;
			if (flag)
			{
				bool flag2 = streamReader.BaseStream != null;
				if (flag2)
				{
					result = streamReader;
				}
				else
				{
					result = new StreamReader(filePath);
				}
			}
			else
			{
				streamReader = new StreamReader(filePath);
				this._readers.Add(filePath, streamReader);
				result = streamReader;
			}
			return result;
		}

		// Token: 0x06000CBC RID: 3260 RVA: 0x000067CB File Offset: 0x000049CB
		public void CloseStreamReader(StreamReader reader)
		{
			reader.Close();
			reader.Dispose();
		}

		// Token: 0x06000CBD RID: 3261 RVA: 0x00038A90 File Offset: 0x00036C90
		public void CloseAllReaders()
		{
			foreach (StreamReader streamReader in this._readers.Values)
			{
				bool flag = streamReader != null;
				if (flag)
				{
					streamReader.Close();
					streamReader.Dispose();
				}
			}
			this._readers.Clear();
		}

		// Token: 0x040007C0 RID: 1984
		private readonly Dictionary<string, StreamWriter> _writers = new Dictionary<string, StreamWriter>();

		// Token: 0x040007C1 RID: 1985
		private readonly Dictionary<string, StreamReader> _readers = new Dictionary<string, StreamReader>();

		// Token: 0x040007C2 RID: 1986
		private static bool _isEncryptionEnabled;
	}
}
